home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome_100_percent.pak / Unnamed File 000042.txt < prev    next >
Text File  |  2013-04-03  |  2KB  |  46 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Custom bindings for the storage API.
  6.  
  7. var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
  8. var normalizeArgumentsAndValidate =
  9.     require('schemaUtils').normalizeArgumentsAndValidate
  10. var sendRequest = require('sendRequest').sendRequest;
  11.  
  12. chromeHidden.registerCustomType('storage.StorageArea', function() {
  13.   function extendSchema(schema) {
  14.     var extendedSchema = schema.slice();
  15.     extendedSchema.unshift({'type': 'string'});
  16.     return extendedSchema;
  17.   }
  18.  
  19.   function StorageArea(namespace, schema) {
  20.     // Binds an API function for a namespace to its browser-side call, e.g.
  21.     // storage.sync.get('foo') -> (binds to) ->
  22.     // storage.get('sync', 'foo').
  23.     //
  24.     // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or
  25.     // even generate) for other APIs that need to do this. Same for other
  26.     // callers of registerCustomType().
  27.     var self = this;
  28.     function bindApiFunction(functionName) {
  29.       self[functionName] = function() {
  30.         var funSchema = this.functionSchemas[functionName];
  31.         var args = Array.prototype.slice.call(arguments);
  32.         args = normalizeArgumentsAndValidate(args, funSchema);
  33.         return sendRequest(
  34.             'storage.' + functionName,
  35.             [namespace].concat(args),
  36.             extendSchema(funSchema.definition.parameters),
  37.             {preserveNullInObjects: true});
  38.       };
  39.     }
  40.     var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
  41.     apiFunctions.forEach(bindApiFunction);
  42.   }
  43.  
  44.   return StorageArea;
  45. });
  46.